package com.jhgsys.internal.hazard.task;

import com.jhgsys.internal.common.utils.SpringContextUtil;
import com.jhgsys.internal.hazard.entity.HazardExamine;
import com.jhgsys.internal.hazard.service.IHazardExamineService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

/**
 * 排班定时任务
 * @author zhangwei
 * @date 2024-08-27 13:40:45
 */
@Slf4j
@Component
public class HazardExamineTask {
    /**
     * 定时任务，安全检查到期后状态设为已关闭
     * @author admin
     * @date 2024-09-29 14:13:44
     */
    public void changeHazardExamineStatus(){
        log.info("定时任务，安全检查到期后状态设为已关闭-----开始执行");
        IHazardExamineService hazardExamineService = SpringContextUtil.getBean(IHazardExamineService.class);
        List<HazardExamine> hazardExamineList = hazardExamineService.findHazardExamineList(new HazardExamine());
        hazardExamineList.forEach(d ->{
            if(null != d.getEndDate() && d.getEndDate().compareTo(new Date())<0){
                d.setStatus("4");
                hazardExamineService.updateById(d);
            }
        });
        log.info("定时任务，安全检查到期后状态设为已关闭-----执行结束");
    }

}
